<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算用户全名</title>
</head>
<body>
    <div id="app">
        姓：<input type="text" v-model="firstname" /><br/>
        名：<input type="text" v-model="lastname" /><br>
        姓名：<input type="text" v-model="fullname"/><br/>
        {{fullname}}<br/>
        <input type="text" v-model="fullname2"/>
    </div>
    <script src="vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data() {
                return {
                    firstname: '二狗子',
                    lastname: '李',
                }
            },
            computed: {
                fullname(){
                    return this.firstname+this.lastname;
                },
                fullname2: {
                    get(){
                        console.log('fullname计算属性')
                        return this.firstname + ' ' + this.lastname
                    },
                    set(value){
                        console.log('输入的是：'+value)
                        const names = value.split(' ')
                        this.firstname = names[0]
                        this.lastname = names[1]
                    }
                }
            }
        })
    </script>
</body>
</html>